Skip to content

Scan content of $CARGO_HOME/bin on restore instead of relying on cargo install metadata #325

Merged
Swatinem merged 1 commit into
Swatinem:masterfrom
clechasseur:feat/cargo-binstall-support
Apr 12, 2026
Merged

Scan content of $CARGO_HOME/bin on restore instead of relying on cargo install metadata #325
Swatinem merged 1 commit into
Swatinem:masterfrom
clechasseur:feat/cargo-binstall-support

Conversation

@clechasseur
Copy link
Copy Markdown
Contributor

The current implementation of getCargoBins to check which binary is installed in $CARGO_HOME/bin checks the content of $CARGO-HOME/.crates2.json to determine which binary is preinstalled. When saving cache, all binaries not found in that file are removed to avoid caching them.

This means, however, that anything installed via a mean other than cargo install (like for example via cargo-binstall) won't be cached.

This PR changes the logic: now, when restoring cache, the $CARGO_HOME/bin directory is scanned and all files there are kept in the action state. When saving the cache post-install, all binaries that were in the directory at the beginning are removed; all others are cached. This allows the use of something like cargo-binstall or taiki-e/install-action, while still benefiting from caching.

I've also added a new workflow to test with cargo-binstall.

Let me know if there's something I should update as well.

Instead of relying on `.crates2.json` to know which binaries are installed,
scan the bin directory and save the result in the action's state.

- run: rustup toolchain install stable --profile minimal --no-self-update

- uses: cargo-bins/cargo-binstall@v1.17.9
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case this helps, that tag is linked to an immutable release and it therefore cannot be modified. That is why I pinned it there; otherwise I would've pinned to a commit hash.

Comment on lines +33 to +34
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need the github token? I couldn’t find any docs that mention this, and I would prefer to rather remove this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not strictly required, but if cargo-binstall downloads binaries from GitHub, it will try to use a GitHub token to avoid hitting more stringent API rate limits. It's possible to pass --github-token on the command-line, otherwise the fallback is to check the GITHUB_TOKEN environment variable.

This is documented in HELP.md, although admittedly not that clearly.

Before I added this, I often hit rate limits in my CI workflows. It's possible that yours wouldn't be that affected, however.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the explanation. This looks good to me.

@Swatinem Swatinem merged commit ed5e89b into Swatinem:master Apr 12, 2026
34 of 36 checks passed
francisdb added a commit to francisdb/vpin that referenced this pull request May 14, 2026
The new GitHub macOS runner image (actions/runner-images#14037) ships a
rustup layout where $CARGO_HOME/bin contains proxies that, once round-
tripped through rust-cache's bin scanner (introduced in v2.9.0 by
Swatinem/rust-cache#325), restore as aliases to `rustup-init`. After
cache restore, `cargo build` then dispatches as `rustup-init` and dies
with "unexpected argument 'build'".

Setting cache-bin: false on the build matrix step keeps the toolchain
proxies installed by dtolnay/rust-toolchain intact across runs. Only
applied to the build matrix; the wasm jobs legitimately want bin caching
for their `cargo install wasmtime-cli` / `cargo install wasm-bindgen-cli`
steps and aren't affected (they run on ubuntu-latest).

See Swatinem/rust-cache#341
pull Bot pushed a commit to thompson-tomo/otel-arrow that referenced this pull request May 15, 2026
…cos-latest (open-telemetry#2978)

## Problem

CI `clippy (*, macos-latest)` (and other macOS rust steps) started
failing today across many PRs with:

```
error: error: unexpected argument 'clippy' found
Usage: rustup-init[EXE] [OPTIONS]
```

## Root cause

GitHub rolled out a new macos-latest runner image today
([actions/runner-images#14037](actions/runner-images#14037))
that changed how the `rustc`/`cargo` rustup proxy binaries are set up.
Combined with
[Swatinem/rust-cache#325](Swatinem/rust-cache#325)
(which made `cache-bin: true` the default in v2.8+), the cached
`$CARGO_HOME/bin/` from previous runs gets restored over the
freshly-installed proxies, leaving `cargo` dispatching to `rustup-init`
behavior instead of the real cargo.

Tracked upstream:
[Swatinem/rust-cache#341](Swatinem/rust-cache#341).

## Fix

Set `cache-bin: false` on all 7 `Swatinem/rust-cache` invocations in
`.github/workflows/rust-ci.yml`. This is the workaround confirmed by the
upstream issue reporter. We don't `cargo install` any binaries that need
caching, so this loses no useful caching.
guancioul pushed a commit to guancioul/otel-arrow that referenced this pull request May 16, 2026
…cos-latest (open-telemetry#2978)

## Problem

CI `clippy (*, macos-latest)` (and other macOS rust steps) started
failing today across many PRs with:

```
error: error: unexpected argument 'clippy' found
Usage: rustup-init[EXE] [OPTIONS]
```

## Root cause

GitHub rolled out a new macos-latest runner image today
([actions/runner-images#14037](actions/runner-images#14037))
that changed how the `rustc`/`cargo` rustup proxy binaries are set up.
Combined with
[Swatinem/rust-cache#325](Swatinem/rust-cache#325)
(which made `cache-bin: true` the default in v2.8+), the cached
`$CARGO_HOME/bin/` from previous runs gets restored over the
freshly-installed proxies, leaving `cargo` dispatching to `rustup-init`
behavior instead of the real cargo.

Tracked upstream:
[Swatinem/rust-cache#341](Swatinem/rust-cache#341).

## Fix

Set `cache-bin: false` on all 7 `Swatinem/rust-cache` invocations in
`.github/workflows/rust-ci.yml`. This is the workaround confirmed by the
upstream issue reporter. We don't `cargo install` any binaries that need
caching, so this loses no useful caching.
guancioul pushed a commit to guancioul/otel-arrow that referenced this pull request May 16, 2026
…cos-latest (open-telemetry#2978)

## Problem

CI `clippy (*, macos-latest)` (and other macOS rust steps) started
failing today across many PRs with:

```
error: error: unexpected argument 'clippy' found
Usage: rustup-init[EXE] [OPTIONS]
```

## Root cause

GitHub rolled out a new macos-latest runner image today
([actions/runner-images#14037](actions/runner-images#14037))
that changed how the `rustc`/`cargo` rustup proxy binaries are set up.
Combined with
[Swatinem/rust-cache#325](Swatinem/rust-cache#325)
(which made `cache-bin: true` the default in v2.8+), the cached
`$CARGO_HOME/bin/` from previous runs gets restored over the
freshly-installed proxies, leaving `cargo` dispatching to `rustup-init`
behavior instead of the real cargo.

Tracked upstream:
[Swatinem/rust-cache#341](Swatinem/rust-cache#341).

## Fix

Set `cache-bin: false` on all 7 `Swatinem/rust-cache` invocations in
`.github/workflows/rust-ci.yml`. This is the workaround confirmed by the
upstream issue reporter. We don't `cargo install` any binaries that need
caching, so this loses no useful caching.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants